package app

import (
	"github.com/go-redis/redis"
	"go-demo/common/global"
	"log"
)

type Redis struct{}

func (redis Redis) Load() {
	client := connectRedis()
	global.App.Redis = client
}

func connectRedis() *redis.Client {
	// redis 配置
	var (
		addr     = global.App.Config.RedisConfig.Addr
		password = global.App.Config.RedisConfig.Password
		db       = global.App.Config.RedisConfig.Db
	)

	// 连接redis
	client := redis.NewClient(&redis.Options{
		Addr:     addr,     //ip + 端口
		Password: password, // redis 密码
		DB:       db,       //数据库
	})
	log.Println("redis数据库 连接成功", client)

	return client
}
